<template>
  <div class="income">
    <div class="income_info borderbox clearfix">
      <div class="left_info">
        <div class="head_text front-color">
          <div class="headTab clearfix">
            <div class="fontsize24 pointer tabDiv" :class="{tabActive: infoOrFlashTab === 'income'}" @click="infoOrFlash('income')">{{$t('myAdd.income.bzuIncomeTitle', {coin: getZoologySymbol})}}</div>
            <div class="fontsize24 pointer tabDiv" :class="{tabActive: infoOrFlashTab === 'flashBZU'}"  @click="infoOrFlash('flashBZU')">{{$t('myAdd.income.exchangeSymbol', {getZoologySymbol: getZoologySymbol})}}</div>
            <div class="back pointer" @click="goBack">< {{$t('myAdd.income.goBack')}}</div>
          </div>
          <div class="des" v-show="infoOrFlashTab === 'income'" :class="{hidden: !seeMore && zoology_description}">
            <div v-html="zoology_description"></div>
            <span class="seeMore pointer" @click="seeMore = !seeMore" v-show="zoology_description && zoology_descriptionLeng > 300">{{seeMoreOrCollapse}}</span>
          </div>
          <!-- flashBZU -->
          <flashBZU
            v-if="infoOrFlashTab === 'flashBZU'"
            :zoologyUserInfoData="zoologyUserInfoData"
            :getZoologySymbol="getZoologySymbol"
            @reGetRecordInfo="reGetRecordInfo"
          ></flashBZU>
        </div>
        <!-- 余额  立即兑换 -->
        <div class="operates front-color borderbox" v-show="infoOrFlashTab === 'income'">
          <div class="balance clearfix">
            <div class="available borderbox" :class="{floatLeft: zoologyUserInfoData.isLock}">
              <div class="balance_text">
                <span class="balance_text_coin">{{$t('myAdd.income.holdAmount')}} ({{getZoologySymbol}})<span class="symbolIndex" v-if="false">{{$t('myAdd.income.symbolIndex')}}: {{unit}} {{zoologyUserInfoData.symbolIndex}}</span></span>
              </div>
              <div class="balance_num">{{zoologyUserInfoData.balance}}</div>
              <div class="balance_income"><span>{{$t('myAdd.income.totalIncome')}}:</span><span> {{zoologyUserInfoData.earnings}} {{zoologyUserInfoData.earningsSymbol}}</span></div>
              <div class="balance_btn">
                <button @click="goToFlashBZU">{{$t('myAdd.income.redeemNow')}}</button>
              </div>
            </div>
            <div class="locked" :class="{floatLeft: zoologyUserInfoData.isLock}" v-show="zoologyUserInfoData.isLock">
              <div class="balance_text"><span class="balance_text_coin">{{$t('myAdd.income.lockedAmount')}} ({{getZoologySymbol}})</span></div>
              <div class="balance_num">{{zoologyUserInfoData.lockQuantity}}</div>
            </div>
          </div>
          <div class="rec_code">
            <div class="rec_code_text">{{$t('myAdd.income.excluInviteCode')}}</div>
            <div class="rec_code_condition" v-if="!zoologyUserInfoData.isRerralCode">{{zoologyUserInfoData.referralCode}}</div>
            <div class="rec_code_btn" v-if="!zoologyUserInfoData.isRerralCode"><button @click="goToFlashBZU">{{$t('myAdd.income.getItNow')}}</button></div>
            <div class="isRerralCode" v-if="zoologyUserInfoData.isRerralCode">{{zoologyUserInfoData.referralCode}}</div>
            <div class="copy_code_btn rec_code_btn" v-if="zoologyUserInfoData.isRerralCode">
              <button @click="copyRecommendCode">{{$t('myAdd.income.copyRecommendCode')}}</button>
              <input type="text" class="recommendCodeInp" ref="recommendCode" :value="zoologyUserInfoData.referralCode" name="code">
            </div>
          </div>
        </div>
        <!-- 节点 -->
        <div class="node front-color borderbox"  v-if="false">
          <div class="first_node">
            <div class="text">
              一级节点
            </div>
            <div class="people_num">
              <span class="numV">{{zoologyUserInfoData.fCount}}</span>
              <span class="numT">人</span>
              <span class="effective">{{zoologyUserInfoData.fValidCount}}有效</span>
            </div>
            <div class="total_income">
              <span>累计收益:</span>
              <span>{{zoologyUserInfoData.fEarnings}} {{zoologyUserInfoData.earningsSymbol}}</span>
            </div>
          </div>
          <div class="second_node">
            <div class="text">
              二级节点
            </div>
            <div class="people_num">
              <span class="numV">{{zoologyUserInfoData.sCount}}</span>
              <span class="numT">人</span>
              <span class="effective">{{zoologyUserInfoData.sValidCount}}有效</span>
            </div>
            <div class="total_income">
              <span>累计收益:</span>
              <span>{{zoologyUserInfoData.sEarnings}} {{zoologyUserInfoData.earningsSymbol}}</span>
            </div>
          </div>
          <div class="third_node">
            <div class="text">
              三级节点
            </div>
            <div class="people_num">
              <span class="numV">{{zoologyUserInfoData.iCount}}</span>
              <span class="numT">人</span>
              <span class="effective">{{zoologyUserInfoData.iValidCount}}有效</span>
            </div>
            <div class="total_income">
              <span>累计收益:</span>
              <span>{{zoologyUserInfoData.iEarnings}} {{zoologyUserInfoData.earningsSymbol}}</span>
            </div>
          </div>
        </div>
        <!-- rule -->
        <div class="rule front-color borderbox" v-if="false">
          <h1>{{$t('myAdd.income.tradeRule')}}</h1>
          <p v-for="(item, index) in zoology_earnings_descriptionArr" :key="index">{{item}}</p>
        </div>
        <!-- 明细 -->
        <div class="incomeDetail front-color borderbox">
          <h1 class="detail_title">
            {{$t('myAdd.income.detail')}}
          </h1>
          <div class="tab clearfix">
            <ul class="left">
              <li :class="{activeTab: tabActive === 'exchangeD'}" class="pointer" @click="changeTab('exchangeD')">{{$t('myAdd.income.transactionDetails')}}</li>
              <li :class="{activeTab: tabActive === 'incomeD'}" class="pointer" @click="changeTab('incomeD')">{{$t('myAdd.income.breakIncome')}}</li>
            </ul>
            <div class="right">
              <Datepicker
                :value="dataTimePickerValue"
                name="uniquename"
                :inline="false"
                :minimumView="'month'"
                :maximumView="'month'"
                @selected="chooseMonth"
                :language="dataTimePickerLanguage"
                format="yyyy-MM"
                :disabledDates="disabledDates"
              >
              </Datepicker>
              <span class="iconSpan"><i class="icon-calendar"></i></span>
            </div>
             <div class="right" v-if="tabActive === 'incomeD' && incomeAllQuantity">
              <span class="total_add">+{{incomeAllQuantity}} {{incomeEarningsSymbol}}</span>
            </div>
            <div class="right" v-if="tabActive === 'exchangeD' && exchangeAllQuantity">
              <span class="total_add">+{{exchangeAllQuantity}} {{exchangeGetSymbol}}</span>
            </div>
          </div>
          <div class="table">
            <table class="income_detail" v-if="tabActive === 'incomeD'">
              <thead>
                <tr>
                  <th class="time borderbox">{{$t('myAdd.income.time')}}</th>
                  <th class="run_water borderbox">{{$t('myAdd.income.detail')}}</th>
                  <th class="level">
                    <inline-input
                      v-bind:property = "formList.incomeType"
                      v-model = "formList.incomeType.value"
                      v-on:onevents = "somethings">
                    </inline-input>
                  </th>
                  <th class="income">{{$t('myAdd.income.incomeCoin')}}</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(item, index) in earningsRecordData" :key="index">
                  <td class="time">{{item.ctime}}</td>
                  <td class="run_water"><span v-show="incomeEarningsType === '1'">{{item.username}}</span> {{item.typeDo}} {{item.exchangeQuantity}} {{item.exchangeSymbol}}</td>
                  <td class="level">{{typeTotext(item.type)}}</td>
                  <td class="income">+{{item.earningQuantity}} {{item.earningSymbol}}</td>
                </tr>
              </tbody>
            </table>
            <noData v-if="tabActive === 'incomeD' && !earningsRecordDataLeng"></noData>
            <VPagination
              v-if="(incomeDetailPage.count/incomeDetailPage.pageSize) > 1 && tabActive === 'incomeD'"
              :total="incomeDetailPage.count"
              :current-page='incomeDetailPage.page'
              :display='incomeDetailPage.pageSize'
              @pagechange="incomeDetailPageChange($event)" class="page">
            </VPagination>
            <table class="exchange_detail" v-if="tabActive === 'exchangeD'">
              <thead>
                <tr>
                  <th class="time borderbox">{{$t('myAdd.income.time')}}</th>
                  <th class="flashNum">{{$t('myAdd.income.flashBZU', {coin: exchangeGetSymbol})}}</th>
                  <th class="exchange_run_water borderbox clearfix">
                    <inline-input
                      v-bind:property = "formList.currency"
                      v-model = "formList.currency.value"
                      v-on:onevents = "somethings">
                    </inline-input>
                  </th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(item, index) in exchangeRecordData" :key="index" class="pointer" @click="getRecodeDetail(item.id)">
                  <td class="time borderbox">{{item.ctime}}</td>
                  <td class="flashNum">+{{item.getQuantity}}</td>
                  <td class="exchange_run_water borderbox">{{$t('myAdd.income.pay')}} {{item.payQuantity}} {{item.paySymbol}}</td>
                </tr>
              </tbody>
            </table>
            <noData v-if="tabActive === 'exchangeD' && !exchangeRecordDataLeng"></noData>
            <VPagination
              v-if="(exchangeRecodePage.count/exchangeRecodePage.pageSize) > 1 && tabActive === 'exchangeD'"
              :total="exchangeRecodePage.count"
              :current-page='exchangeRecodePage.page'
              :display='exchangeRecodePage.pageSize'
              @pagechange="exchangeRecodePageChange($event)" class="page">
            </VPagination>
          </div>
        </div>
      </div>
      <!-- 社区 -->
      <div class="right_info front-color borderbox">
        <div class="community_head">
          <h1>{{$t('myAdd.income.myCommunity')}}</h1>
          <div class="numberOne clearfix">
            <div class="avatar"><img :src="myCommunityData.photoUrl || defaultHeadImg" alt=""></div>
            <div class="userName borderbox">
              <p class="name">{{userName}}</p>
              <p class="ctime">{{myCommunityData.time || '--'}}</p>
            </div>
            <div class="people_num borderbox">
              <p class="total_num">{{myCommunityData.exchangeQuantity}}</p>
              <p class="effective_num">{{$t('myAdd.income.effective', {exchangeSymbol: myCommunityData.exchangeSymbol})}}</p>
            </div>
          </div>
        </div>
        <div class="list">
          <ul class="list_ul">
            <li class="clearfix borderbox" v-for="(item, index) in myCommunityData.mapList" :key="index">
              <div class="index">
                {{index + 1}}
              </div>
              <div class="avatar">
                <img :src="item.photoUrl || defaultHeadImg" alt="">
              </div>
              <div class="userName borderbox">
                <p class="name">{{item.username}}</p>
                <p class="ctime">{{item.time}}</p>
              </div>
              <div class="people_num borderbox">
                <p class="total_num">{{item.exchangeQuantity}}</p>
                <p class="effective_num">{{$t('myAdd.income.effective', {exchangeSymbol: item.exchangeSymbol})}}</p>
              </div>
            </li>
          </ul>
          <noData v-if="!myCommunityDataLeng"></noData>
          <VPagination
            v-if="(myCommunityPage.count/myCommunityPage.pageSize) > 1"
            :total="myCommunityPage.count"
            :current-page='myCommunityPage.page'
            :display='myCommunityPage.pageSize'
            @pagechange="myCommunityPageChange($event)" class="page">
          </VPagination>
        </div>
      </div>
    </div>
    <!-- 兑换明细 -->
    <elDialog
      title= ''
      :flag= 'detailAlert'
      name= 'detailAlert'
      :width='450'
      :dialogClose='closeDialog'>
      <div class="detailTitle" slot="operation">
        {{$t('myAdd.income.flashDetail')}}
      </div>
      <div class="detailAlertData" slot="content">
        <div class="side"><span>{{detailAlertData.paySymbol}}</span><i class="icon-uniE958"></i><span>{{detailAlertData.getSymbol}}</span></div>
        <div class="data">
          <p><span class="text">{{$t('myAdd.income.payAmount')}}</span><span class="num">{{detailAlertData.payQuantity}} {{detailAlertData.paySymbol}}</span></p>
          <p><span class="text">{{$t('myAdd.income.getQuantity')}}</span><span class="num">{{detailAlertData.getQuantity}} {{detailAlertData.getSymbol}}</span></p>
          <p><span class="text">{{$t('myAdd.income.rate')}}</span><span class="num">{{detailAlertData.rate}}</span></p>
          <p><span class="text">{{$t('myAdd.income.exchangeNumber')}}</span><span class="num">{{detailAlertData.exchangeNumber}}</span></p>
          <p><span class="text">{{$t('myAdd.income.time')}}</span><span class="num">{{detailAlertData.ctime}}</span></p>
        </div>
      </div>
      <div class="detailAlertFooter" slot="options">
        <button @click="closeDialog" class="cancel">{{$t('myAdd.income.close')}}</button>
      </div>
    </elDialog>
    <b v-if="baseData"></b>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import VPagination from '@/components/common/pagination'
import noData from '@/components/addPage/common/noData'
import elDialog from '@/components/common/addCommon/dialog'
import InlineInput from '@/components/common/inlineInput'
import headImg from '@/assets/img/otc/portrait.png'
import Datepicker from 'vuejs-datepicker'
import {en, zh, ko} from 'vuejs-datepicker/dist/locale'
import flashBZU from '@/components/addPage/income/flashBZU'

export default {
  name: 'income',
  components: { VPagination, noData, elDialog, InlineInput, Datepicker, flashBZU },
  data () {
    return {
      secondClick: true,
      getZoologySymbol: '', // 平台币种
      zoology_description: '', // 生态权益描述
      // zoology_earnings_description: '', // 生态权益规则
      // zoology_earnings_descriptionArr: [], // 通过 ';' 把规则切割成 一条 一条
      zoologyUserInfoData: {
        iValidCount: 0, // 无限级有效推荐人数
        sValidCount: 0, //  二级有效推荐人数
        sEarnings: 0, // 二级收益
        earnings: '', // 总收益
        balance: 0, // 持有额度(BZU)
        iEarnings: 0, // 无限级收益
        fEarnings: 0, // 一级收益
        fValidCount: 0, // 一级有效推荐人数
        referralCode: '', // 获取推荐码条件
        iCount: 0, // 无限级推荐人数
        fCount: 0, // 一级推荐人数
        sCount: 0, // 二级推荐人数
        giveQuantity: 0, // 赠金(套餐赠送)
        exchangeSymbol: '', // 兑换币种
        earningsSymbol: '', // 收益币种
        isRerralCode: false, // 是否有推荐码(true:有 false:没有)
        paySymbolList: [], // 兑换币种集合
        indexType: null,
        symbolIndex: null,
        isLock: null,
        lockQuantity: null
      },
      tabActive: 'exchangeD',
      incomeDetailPage: { // 收益记录分页
        pageSize: 10,
        count: '',
        page: 1
      },
      exchangeRecodePage: { // 交易记录分页
        pageSize: 10,
        count: '',
        page: 1
      },
      myCommunityPage: {
        pageSize: 10,
        count: '',
        page: 1
      },
      earningsRecordData: [], // 收益记录
      exchangeRecordData: [], // 交易记录明细
      incomeAllQuantity: 0,
      incomeEarningsSymbol: null,
      incomeEarningsType: '', // 类型
      exchangeAllQuantity: 0,
      exchangeGetSymbol: null,
      exchangeSymbol: '', // 兑换币种
      formList: {},
      detailAlert: false, // 交易记录详情弹窗
      detailAlertData: { // 弹窗详情的信息
        paySymbol: null,
        payQuantity: null,
        getSymbol: null,
        getQuantity: null,
        exchangeNumber: null,
        ctime: null,
        rate: null
      },
      // 我的社区数据
      myCommunityData: {
        photoUrl: '',
        time: '',
        username: '',
        mapList: [],
        exchangeQuantity: 0,
        exchangeSymbol: '--'
      },
      defaultHeadImg: headImg,
      userInfo: null,
      coinList: null,
      dataTimePickerValue: this.getLocalTime(),
      dataTimePickerLanguage: en,
      disabledDates: { // 限制时间选择范围  是 2018-12-31 --- 当前月
        to: new Date('Mon Dec 31 2018 19:47:00 GMT+0800 (中国标准时间)'),
        from: new Date(new Date().getTime() + 1000 * 60 * 60 * 24),
        daysOfMonth: undefined
      },
      axiosDate: this.dateProcessing(new Date()), // 获取收益明细 和 交易明细 的 年月 参数
      infoOrFlashTab: 'income', // 页面顶部当前tab
      seeMore: false
    }
  },
  created () {
    this.formList = this.formList_obj
  },
  mounted () {
    this.setDateTimePickerLang(localStorage.getItem('lan')) // 设置 时间选择 插件 的  语言
    this.getZoologySymbol = this._P.fixUrl('name')
    this.zoologyUserInfo()
    this.exchangeRecord() // 交易记录
  },
  watch: {
    'formList_obj' (val) {
      this.formList = val
    },
    tabActive (val) {
      if (val === 'incomeD') {
        this.earningsRecord()
      } else if (val === 'exchangeD') {
        this.exchangeRecord()
      }
    },
    'formList.incomeType.value' (newV) {
      if (newV) {
        this.incomeDetailPage.page = 1
        if (newV === '0') {
          this.incomeEarningsType = null
        } else {
          this.incomeEarningsType = newV
        }
        this.earningsRecord()
      }
    },
    'formList.currency.value' (newV) {
      if (newV) {
        this.exchangeRecodePage.page = 1
        if (newV === 'text') {
          this.exchangeSymbol = ''
        } else {
          this.exchangeSymbol = newV
        }
        this.exchangeRecord()
      }
    },
    userInfo (newV) {
      newV && this.getUserWanted()
    },
    coinList (val) {
      if (val && this.zoologyUserInfoData.balance) {
        this.zoologyUserInfoData.balance = this._P.fixD(this.zoologyUserInfoData.balance, val[this.getZoologySymbol].showPrecision)
        this.zoologyUserInfoData.balance = this._P.lastD(this.zoologyUserInfoData.balance)
      }
    },
    // 监听 语言切换
    '$store.state.baseData._lan' (val, old) {
      if (old) {
        this.setDateTimePickerLang(val)
      }
    }
  },
  computed: {
    ...mapState({
      baseData ({baseData}) {
        if (baseData.isReady) {
          // this.zoology_earnings_description = baseData.zoology_earnings_description
          // this.zoology_earnings_descriptionArr = this.zoology_earnings_description.split(';')
          this.userInfo = baseData._user
          this.coinList = baseData._coinList
          this.myCommunity()
          return baseData
        } else {
          return false
        }
      }
    }),
    userName () {
      if (this.userInfo) {
        return this.userInfo.nickName
      }
    },
    formList_obj () {
      return {
        incomeType: { // 收益类型
          title: '',
          placeholder: '',
          formType: 'select',
          name: 'incomeType',
          value: '0',
          optionList: [
            {value: this.Internationalization.type, code: '0'},
            {value: this.Internationalization.ecologicalIncome, code: '1'},
            {value: this.Internationalization.holdingMoney, code: '2'},
            {value: this.Internationalization.lockMining, code: '3'},
            {value: this.Internationalization.purchaseGift, code: '4'},
          ]
        },
        currency: { // 币种选择
          title: '',
          placeholder: '',
          formType: 'select',
          name: 'currency',
          value: 'text',
          optionList: this.formCurrencyOptionList
        }
      }
    },
    earningsRecordDataLeng () {
      return this.earningsRecordData.length
    },
    exchangeRecordDataLeng () {
      return this.exchangeRecordData.length
    },
    myCommunityDataLeng () {
      return this.myCommunityData.mapList.length
    },
    Internationalization () {
      return {
        type: this.$t('myAdd.income.type'), // 类型
        ecologicalIncome: this.$t('myAdd.income.ecologicalIncome'), // 生态收益
        holdingMoney: this.$t('myAdd.income.holdingMoney'), // 持币生息
        lockMining: this.$t('myAdd.income.lockMining'), // 锁仓挖矿
        purchaseGift: this.$t('myAdd.income.purchaseGift'), // 购买赠送
        detail: this.$t('myAdd.income.detail'), // 明细
        copySuc: this.$t('myAdd.income.copySuc'), // 复制成功
        seeMore: this.$t('myAdd.income.seeMore'), // 查看更多
        collapse: this.$t('myAdd.income.collapse') // 查看更多
      }
    },
    formCurrencyOptionList () {
      if (this.zoologyUserInfoData.paySymbolList.length > 0) {
        let arr = [
          {value: this.Internationalization.detail, code: 'text'}
        ]
        this.zoologyUserInfoData.paySymbolList.forEach(item => {
          let obj = { value: '', code: '' }
          obj.value = item
          obj.code = item
          arr.push(obj)
        })
        return arr
      }
    },
    unit () {
      let unit = null
      this.zoologyUserInfoData.indexType === 0 && (unit = '￥')
      this.zoologyUserInfoData.indexType === 1 && (unit = '$')
      return unit
    },
    seeMoreOrCollapse () {
      return this.seeMore ? this.Internationalization.collapse : this.Internationalization.seeMore
    },
    zoology_descriptionLeng () {
      return this.zoology_description.length
    }
  },
  methods: {
    closeDialog () {
      this.detailAlert = false
    },
    // 生态权益个人中心
    zoologyUserInfo () {
      this.axios({
        url: this.$store.state.url.openPlatform.user_info,
        header: {},
        method: 'POST',
        params: {
          exchangeSymbol: this.getZoologySymbol
        }
      }).then(res => {
        if (res.code.toString() === '0') {
          this.zoologyUserInfoData.iValidCount = res.data.iValidCount
          this.zoologyUserInfoData.sValidCount = res.data.sValidCount
          this.zoologyUserInfoData.sEarnings = res.data.sEarnings
          this.zoologyUserInfoData.earnings = res.data.earnings
          this.zoologyUserInfoData.balance = res.data.balance
          if (this.coinList) {
            this.zoologyUserInfoData.balance = this._P.fixD(this.zoologyUserInfoData.balance, this.coinList[this.getZoologySymbol].showPrecision)
            this.zoologyUserInfoData.balance = this._P.lastD(this.zoologyUserInfoData.balance)
          }
          this.zoologyUserInfoData.iEarnings = res.data.iEarnings
          this.zoologyUserInfoData.fEarnings = res.data.fEarnings
          this.zoologyUserInfoData.fValidCount = res.data.fValidCount
          this.zoologyUserInfoData.referralCode = res.data.referralCode
          this.zoologyUserInfoData.iCount = res.data.iCount
          this.zoologyUserInfoData.fCount = res.data.fCount
          this.zoologyUserInfoData.sCount = res.data.sCount
          this.zoologyUserInfoData.giveQuantity = res.data.giveQuantity
          this.zoologyUserInfoData.exchangeSymbol = res.data.exchangeSymbol
          this.zoologyUserInfoData.earningsSymbol = res.data.earningsSymbol
          this.zoologyUserInfoData.isRerralCode = res.data.isRerralCode
          this.zoologyUserInfoData.paySymbolList = res.data.paySymbolList.split(',')
          this.zoologyUserInfoData.symbolIndex = res.data.symbolIndex
          this.zoologyUserInfoData.indexType = res.data.indexType
          this.zoologyUserInfoData.isLock = Number(res.data.isLock)
          this.zoologyUserInfoData.lockQuantity = Number(res.data.lockQuantity)
          this.zoology_description = res.data.description
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 明细的选项卡切换
    changeTab (type) {
      this.tabActive = type
    },
    // 收益明细
    earningsRecord () {
      if (!this.coinList) {
        return false
      }
      let params = {
        page: this.incomeDetailPage.page,
        pageSize: this.incomeDetailPage.pageSize,
        type: this.incomeEarningsType,
        date: this.axiosDate,
        exchangeSymbol: this.getZoologySymbol
      }
      this.axios({
        url: this.$store.state.url.openPlatform.earnings_record,
        header: {},
        method: 'POST',
        params: params
      }).then(res => {
        if (res.code.toString() === '0') {
          const _this = this
          let data = res.data
          if (!data) {
            this.incomeDetailPage.count = 0
          } else {
            this.incomeDetailPage.count = data.count
            this.incomeAllQuantity = data.allQuantity
            this.earningsRecordData = data.mapList
            this.incomeEarningsSymbol = data.earningsSymbol
            this.earningsRecordData.forEach(item => {
              item.ctime = _this._P.formatTime(item.ctime)
              item.exchangeQuantity = _this._P.fixD(item.exchangeQuantity, _this.coinList[item.exchangeSymbol].showPrecision)
              item.exchangeQuantity = _this._P.lastD(item.exchangeQuantity)

              item.earningQuantity = _this._P.fixD(item.earningQuantity, _this.coinList[data.earningsSymbol].showPrecision)
              item.earningQuantity = _this._P.lastD(item.earningQuantity)
            })
          }
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 交易记录
    exchangeRecord () {
      let params = {
        page: this.exchangeRecodePage.page,
        pageSize: this.exchangeRecodePage.pageSize,
        symbol: this.exchangeSymbol,
        date: this.axiosDate,
        exchangeSymbol: this.getZoologySymbol
      }
      this.axios({
        url: this.$store.state.url.openPlatform.exchange_record,
        header: {},
        method: 'POST',
        params: params
      }).then(res => {
        if (res.code.toString() === '0') {
          const _this = this
          let data = res.data
          if (!data) {
            this.exchangeRecodePage.count = 0
            this.exchangeRecordData = []
          } else {
            this.exchangeRecodePage.count = data.count
            this.exchangeAllQuantity = data.allQuantity
            this.exchangeGetSymbol = data.getSymbol
            this.exchangeRecordData = data.list
            this.exchangeRecordData.forEach(item => {
              item.ctime = _this._P.formatTime(item.ctime)
            })
          }
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 收益记录分页
    incomeDetailPageChange (page) {
      this.incomeDetailPage.page = page
      this.earningsRecord()
    },
    // 交易记录分页
    exchangeRecodePageChange (page) {
      this.exchangeRecodePage.page = page
      this.exchangeRecord()
    },
    // 我的社区分页
    myCommunityPageChange (page) {
      this.myCommunityPage.page = page
      this.myCommunity()
    },
    // 我的社区
    myCommunity () {
      if (!this.getZoologySymbol) {
        return false
      }
      const _this = this
      this.axios({
        url: this.$store.state.url.openPlatform.my_community,
        header: {},
        method: 'POST',
        params: {
          page: this.myCommunityPage.page,
          pageSize: this.myCommunityPage.pageSize,
          exchangeSymbol: this.getZoologySymbol
        }
      }).then(res => {
        if (!res) {
          this.myCommunityData.username = this.userName
        } else if (res.code.toString() === '0') {
          let data = res.data
          this.myCommunityPage.count = data.count
          this.myCommunityData.time = this._P.dateFilter(data.time)
          this.myCommunityData.username = data.username
          this.myCommunityData.mapList = data.mapList
          this.myCommunityData.exchangeQuantity = this._P.fixD(data.exchangeQuantity, this.coinList && this.coinList[data.exchangeSymbol].showPrecision)
          this.myCommunityData.exchangeQuantity = this._P.lastD(this.myCommunityData.exchangeQuantity)
          this.myCommunityData.exchangeSymbol = data.exchangeSymbol
          this.myCommunityData.mapList.forEach(item => {
            item.time = _this._P.dateFilter(item.time)
            item.exchangeQuantity = _this._P.fixD(item.exchangeQuantity, this.coinList && this.coinList[item.exchangeSymbol].showPrecision)
            item.exchangeQuantity = _this._P.lastD(item.exchangeQuantity)
          })
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 获取交易记录数据的详情
    getRecodeDetail (id) {
      this.axios({
        url: this.$store.state.url.openPlatform.exchange_detail,
        header: {},
        method: 'POST',
        params: {
          id: id
        }
      }).then((res) => {
        if (res.code.toString() === '0') {
          let data = res.data.exchange
          this.detailAlertData.id = data.id
          this.detailAlertData.paySymbol = data.paySymbol
          this.detailAlertData.payQuantity = data.payQuantity
          this.detailAlertData.getSymbol = data.getSymbol
          this.detailAlertData.getQuantity = data.getQuantity
          this.detailAlertData.exchangeNumber = data.exchangeNumber
          this.detailAlertData.ctime = data.ctime
          this.detailAlertData.ctime = this._P.formatTime(this.detailAlertData.ctime)
          this.detailAlertData.rate = data.rate
          this.detailAlert = true
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    somethings (data) {},
    typeTotext (type) {
      let text = ''
      switch (type) {
        case 1:
          text = this.Internationalization.ecologicalIncome
          break
        case 2:
          text = this.Internationalization.holdingMoney
          break
        case 3:
          text = this.Internationalization.lockMining
          break
        case 4:
          text = this.Internationalization.purchaseGift
          break
      }
      return text
    },
    // 获取用户信息
    getUserWanted () {
      this.axios({
        url: this.$store.state.otcUrl.personal.person_home_page,
        headers: {},
        params: {
          uid: this.userInfo.id.toString()
        },
        hostType: 'otc',
        method: 'post'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.myCommunityData.photoUrl = res.data.imageUrl
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 获取当前时间
    getLocalTime () {
      return new Date()
    },
    // 日期处理
    dateProcessing (date) {
      function s (t) {
        return t < 10 ? '0' + t : t
      }
      let y = date.getFullYear()
      let m = s(date.getMonth() + 1)
      return y + '-' + m
    },
    // 选择日期
    chooseMonth (e) {
      this.axiosDate !== this.dateProcessing(e) && this.tabActive === 'incomeD' && (this.incomeDetailPage.page = 1) // 更换月份的时候 分页 变为 第一页
      this.axiosDate !== this.dateProcessing(e) && this.tabActive === 'exchangeD' && (this.exchangeRecodePage.page = 1)
      this.axiosDate = this.dateProcessing(e)
      if (this.tabActive === 'incomeD') {
        this.earningsRecord()
      } else if (this.tabActive === 'exchangeD') {
        this.exchangeRecord()
      }
    },
    // 根据当前网站的语言环境 设置 时间选择插件的 语言
    setDateTimePickerLang (val) {
      switch (val) {
        case 'zh_CN':
          this.dataTimePickerLanguage = zh
          break
        case 'en_US':
          this.dataTimePickerLanguage = en
          break
        case 'ko_KR':
          this.dataTimePickerLanguage = ko
          break
        case 'el_GR':
          this.dataTimePickerLanguage = zh
          break
      }
    },
    // 页面顶部选项卡
    infoOrFlash (tab) {
      this.infoOrFlashTab = tab
    },
    // 去兑换
    goToFlashBZU () {
      this.infoOrFlashTab = 'flashBZU'
    },
    // 复制推荐码
    copyRecommendCode () {
      this.$refs.recommendCode.select()
      document.execCommand('copy')
      this.$store.dispatch('setTipState', this.Internationalization.copySuc)
    },
    // flashBZU 触发的事件
    reGetRecordInfo () {
      this.tabActive === 'exchangeD' && this.exchangeRecord()
      this.tabActive === 'incomeD' && this.earningsRecord()
      this.zoologyUserInfo()
      this.myCommunity()
    },
    // 返回上一页
    goBack () {
      this.$router.go(-1)
    }
  }
}
</script>

